!(function ($) {
    $.fn.framework = function (options) {
        var that = this;
        return {
            bootstrapTable: function (options) {
                var DEFAULTS = {
                    height: 700,
                    undefinedText: '-',
                    method: 'get',
                    pagination: true,
                    queryParamsType: "",
                    sidePagination: 'server',
                    pageSize: 10,
                    pageList: [10, 20, 50, 'ALL'],
                    minimumCountColumns: 2,
                    search: true,
                    uniqueId: 'id',
                    toolbar: '#toolbar',
                    responseHandler: function (res) {
                        return {
                            total: res.totalElements,
                            rows: res.content
                        };
                    }
                };
                if (options.url) {
                    options.url = createUrl(options.url);
                }
                $.extend(DEFAULTS, options);
                that.bootstrapTable(DEFAULTS);
            },
            fileInput: function (options) {
                var DEFAULTS = {
                    language: 'zh', // 设置语言
                    maxFileCount: 9, // 表示允许同时上传的最大文件个数
                    allowedFileExtensions: ['jpeg', 'jpg', 'png', 'gif',
                        'bmp', 'tif', 'zip'],// 接收的文件后缀
                    showPreview: true, // 是否显示预览
                    uploadUrl: "/",
                    showUpload: false, // 是否显示上传按钮
                    showCaption: true, // 是否显示标题
                    showClose: false, // 关闭窗口
                    showUploadedThumbs: false,
                    dropZoneEnabled: false, // 是否允许拖拽
                    initialPreviewShowDelete: true, // 修改初始化时显示删除按钮
                    overwriteInitial: false, // 修改时不覆盖原有文件
                    maxImageWidth: 1500,
                    maxImageHeight: 1500,
                    maxFileSize: 14024,
                    previewSettings: {
                        image: {
                            width: "176px",
                        },
                        html: {
                            width: "176px"
                        },
                        text: {
                            width: "176px"
                        },
                        video: {
                            width: "176px"
                        },
                        audio: {
                            width: "176px"
                        },
                        flash: {
                            width: "176px"
                        },
                        object: {
                            width: "176px"
                        },
                        other: {
                            width: "176px"
                        }
                    },
                    browseClass: "btn btn-primary", // 按钮样式
                    defaultPreviewContent: '',
                    previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
                };
                $.extend(DEFAULTS, options);
                that.fileinput(DEFAULTS);
            }
        };
    }
})(jQuery);
function createUrl(url) {
    var pathName = window.document.location.pathname.replace("//", "/");
    var projectName = pathName
        .substring(0, pathName.substr(1).indexOf('/') + 1);
    return projectName + url;
}
var framework = {
    openWindow: function (url, width, height, title, allowScroll) {
        var index = layer.open({
            type: 2, // layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            title: title,
            content: [url.indexOf("http") === 0 ? url : createUrl(url),
                allowScroll || 'yes'], // 不出现滚动条no
            area: [width, height],
            shadeClose: false, // 点击阴影是否关闭
            closeBtn: 1,
            shift: 1, // 目前shift可支持的动画类型有0-6
            maxmin: false
        });
        return index;
    },
    tips: function (msg, obj) {
        if (typeof obj == 'object') {
            layer.tips(msg, obj, {
                tips: [3, '#34A7FF'],
                time: 1000
            })
        } else {
            layer.tips(msg, $("#" + obj), {
                tips: [1, '#34A7FF']
            });
        }
    },
    alert: function (msg) {
        layer.alert(msg);
    },
    successMsg: function (msg) {
        try {
            parent.refresh();
            parent.layer.closeAll('iframe');
            parent.layer.msg(msg);
        } catch (e) {
            refresh();
            layer.msg(msg);
        }
    },
    errorMsg: function (msg) {
        layer.msg(msg);
    },
    fillForm: function ($form, data) {
        for (key in data) {
            var doms = $("[name=" + key + "]", $form);
            if (doms.length) {
                switch ($(doms[0]).attr('type')) {
                    case "input":
                        $(doms[0]).val(data[key]);
                        continue;
                    case "text":
                        $(doms[0]).val(data[key]);
                        continue;
                    case "checkbox":
                        $(doms[0]).attr("checked", data[key]);
                        continue;
                    default:
                        $(doms[0]).val(data[key]);
                }
            }
        }
    }
}